package com.vic.module.controller;


import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.vic.commons.controller.BaseController;
import com.vic.module.bean.User;
import com.vic.module.service.UserService;

@Controller
@RequestMapping(value="/user")
public class UserController extends BaseController{
	
	@Autowired
	private UserService userService;
	
	@ResponseBody
	@RequestMapping(value="/find")
	public Object find(HttpServletRequest request){
		List<Map<String, Object>> list = userService.findBySql("select * from user");
		String str = JSON.toJSONString(list);
		
		return super.success(JSONArray.parseArray(str, User.class));
	}

	@ResponseBody
	@RequestMapping(value="/detail")
	public Object detail(HttpServletRequest request,Integer id){
		return super.success(userService.getById(id));
	}
	
	@ResponseBody
	@RequestMapping(value="/save")
	public Object detail(HttpServletRequest request,User vo){
		return super.success(userService.save(vo));
	}
}
